const http = require('http')
const fs = require('fs')
const path = require('path')

const server = http.createServer()

server.on('request', (req, res) => {
    let url  = req.url

   let fullPath = path.join(__dirname, 'client', url)

   if (url === '/') {
       fullPath = path.join(__dirname, 'client', 'index.html')
   }

   fs.readFile(fullPath, (err, data) => {
       if (err) {
        return res.end(err.message)
           
       }
       return res.end(data)
   })

})

server.listen(3002, () => {
    console.log('listen port 3002.')
})